package com.auxgroup.hr.front.hrverify;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * {"Success":true,"ErrorInfo":"","ProcReturn":[],"Params":[{"parmname":"@returnvalue","parmvalue":"工号TEST00001不存在","isout":true}]}
 * Success : SQL本身执行结果的返回  true 表示语法没有问题执行成功 false 表示语法或参数格式有误接口执行失败
 * ErrorInfo :当参数或接口本身有语法错误时,SQL执行后的错误信息在此显视
 * ProcReturn :接口的数据集返回,如无数据集则空
 * Params 返回调用参数中 isout 为 true 的输出参数列表 parmname:输出参数名称,parmvalue:输出参数的值 //对应POST参数列表中的isout为true值的参数
 * 如执行成功，则值为 成功   否则返回 错误信息
 * <p>
 * Created by nitongqian on 2019/5/14.
 */
public class AuxCheckResponse implements Serializable {
    @JsonProperty(value = "Success")
    private boolean success;
    @JsonProperty(value = "ErrorInfo")
    private String errorInfo;
    @JsonProperty(value = "ProcReturn")
    private List procReturn;
    @JsonProperty(value = "Params")
    private List<AuxCheckParam> params = new ArrayList<>();

    public boolean isChecked(String field, String value) {

        if (this.success && StringUtils.isEmpty(this.errorInfo)) {
            if (this.params == null || this.params.isEmpty()) {
                return true;
            } else {
                if (params.stream().filter(param ->
                        StringUtils.equals(field, param.getParmname()) && StringUtils.equals(value, param.getParmvalue())
                ).findAny().isPresent()) {
                    return true;
                }
            }

        }
        return false;

    }

    public String getValue(String filed) {
        if (this.params != null && !this.params.isEmpty()) {
            for (AuxCheckParam auxCheckParam : params) {
                if (filed.equals(auxCheckParam.getParmname())) {
                    return auxCheckParam.getParmvalue();
                }
            }
        }
        return "";
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getErrorInfo() {
        return errorInfo;
    }

    public void setErrorInfo(String errorInfo) {
        this.errorInfo = errorInfo;
    }

    public List getProcReturn() {
        return procReturn;
    }

    public void setProcReturn(List procReturn) {
        this.procReturn = procReturn;
    }

    public List<AuxCheckParam> getParams() {
        return params;
    }

    public void setParams(List<AuxCheckParam> params) {
        this.params = params;
    }
}
